import { useTableColumnProps } from '/@/hooks/table-column/props'
import { getValueByKey } from 'csui'

/**
 * 使用map映射自动匹配填充
 * @param prop column.prop
 * @param label column.label
 * @param map 映射数据源
 * @param options tableColumn的其他属性
 * @returns tableColumn props
 */
export function useTableColumnMap<
  T extends Record<string, any>,
  P extends keyof T
>(
  prop: P,
  label: string,
  map: Record<string, any>,
  options: UseTableColumnProps<any, T, P> = {}
) {
  return useTableColumnProps<T, P>(prop, label, {
    formatter: (row: T) => getValueByKey(map, row[prop]),
    ...options
  })
}
